﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace lumo.display.animation2D
{
    /// <summary>
    /// LambdaAnimation2D
    /// </summary>
    public class LambdaAnimation2D : IInternalAnimation2D, IAnimation2D
    {
        private Action<object> Action;
        private object CurrentObject = null;
        /// <summary>
        /// Constructor.
        /// </summary>
        /// <param name="CurrentObject">The animated object.</param>
        public LambdaAnimation2D(Action<object> Action, object CurrentObject = null)
        {
            // Set the object.
            this.Action = Action;
            this.CurrentObject = CurrentObject;
            this.Setupped = false;
        }

        /// <summary>
        /// Setup the animations.
        /// </summary>
        /// <param name="ParentObject">The parent object of the animations.</param>
        public void Setup(object ParentObject)
        {
            if (this.CurrentObject == null)
                this.CurrentObject = ParentObject;
            // Set the parent object.
            this.Action(CurrentObject);
            // The object is setupped.
            this.Setupped = true;
        }

        /// <summary>
        /// Setup the animations.
        /// </summary>
        /// <param name="ParentObject">The parent object of the animations.</param>
        public void Reset()
        {
            // The object is setupped.
            this.Setupped = false;
        }

        /// <summary>
        /// Check if it is setupped.
        /// </summary>
        public bool Setupped { get; private set; }

        /// <summary>
        /// Check if animation has finished.
        /// </summary>
        /// <returns>True if it has</returns>
        public bool Finished { get { return this.Setupped; } }

        /// <summary>
        /// Update the animations.
        /// </summary>
        /// <param name="Game"></param>
        public void Update(LumoComponent Game)
        {
            if (!Setupped)
                this.Setup(CurrentObject);
        }
    }
}
